<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'register.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript">
		function chkUname(){
			//1.得到XMLHttpRequest对象
			var xhr = getXhr();
			//2.设置回调函数
			xhr.onreadystatechange = function(){
				//如何返回正常再处理
				if(xhr.readyState == 4 && xhr.status == 200){
					var msg = document.getElementById("msg");
					msg.innerHTML = xhr.responseText;
				}
			};
			//获取用户名值
			var uname = document.getElementsByName("username")[0];
			//3.初始化XMLHttpRequest组件
			xhr.open("get","/ajax01/check.do?username="+uname.value,true);
			//4.发送请求
			xhr.send();
		}
		
		/*
		创建XMLHttpRequest对象
		*/
		function getXhr(){
			if(window.XMLHttpRequest){
				return new XMLHttpRequest();
			}
			if(window.ActiveXObject){
				return new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	</script>
  </head>
  
  <body>
  	<h3>会员注册</h3>
  	<hr />
    <form action="" method="post">
    	用户名:<input type="text" name="username" onblur="chkUname()" />
    	<span id="msg"></span><br />
    	<input type="submit" value="注册" />
    </form>
  </body>
</html>
